﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using VoteUphold;
using System.Text.RegularExpressions;

namespace Provider
{
    /// <summary>
    /// 获取代理 IP,端口
    /// http://www.net.cn/static/customercare/yourIP.asp
    /// </summary>
    public class GetProxy
    {
        private List<WebProxy> ADRESS_PROXY_LIST;

        public GetProxy()
        {
            ADRESS_PROXY_LIST = new List<WebProxy>();


        }

        /// <summary>
        /// 获取1 主机名:端口
        /// </summary>
        /// <returns></returns>
        public static List<string> GetProxyProxycn()
        {
            List<string> hostPortList = new List<string>();
            AdressInfo adressInfo = new AdressInfo()
            {
                Adress = "http://www.proxycn.com/html_proxy/30fastproxy-1.html",
                Directions = "今日最新最快50个HTTP代理列表"
            };
            WebClient web = new WebClient();
            string result = "";
            try
            {
                result = web.DownloadString(adressInfo.Adress);
            }
            catch (Exception)
            {
                return hostPortList;
            }

            //"clip('204.85.191.10:68664');
            string startStr = "\"clip\\('\\d{1,5}\\.\\d{1,5}\\.\\d{1,5}\\.\\d{1,5}:\\d{0,7}";
            MatchData md = new MatchData(startStr, "'\\)", result);
            Match[] matches = md.Matches(System.Text.RegularExpressions.RegexOptions.None);
            for (int i = 0; i < matches.Length; i++)
            {
                string hostPort = matches[i].Value.TrimStart("\"clip\\('".ToCharArray()).TrimEnd("'\\)".ToCharArray());
                hostPortList.Add(hostPort);
            }
            return hostPortList;
        }
    }
}